import torch
import numpy as np

# numpy构建数组
np_data = np.arange(6).reshape((2, 3))
# torch构建张量
torch_data = torch.tensor([[2, 3], [4, 5]])

print('numpy:\n', np_data)
print('torch张量:\n', torch_data)

# tensor转array
print('torch2numpy:\n', torch_data.numpy())

# abs
data = [-1, -2, 1, 2]
# 32bit的float
float_data = torch.FloatTensor(data)
print('abs:\n',
      'numpy:\n', np.abs(data),
      '\ntorch:\n', torch.abs(float_data))

print('sin:\n',
      'numpy:\n', np.sin(data),
      '\ntorch:\n', torch.sin(float_data))
